from django.db import models

from utils.basemodel import BaseModel


# Create your models here.
class OrderInfo(BaseModel):
    # 订单
    order_id = models.CharField(max_length=64, primary_key=True,verbose_name='订单号')
    user = models.ForeignKey('user.UserProfile', on_delete=models.CASCADE, verbose_name='用户')

    total_count = models.IntegerField(default=1, verbose_name='商品数量')
    total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品总金额')
    status = models.SmallIntegerField(default=1, choices=((1, '待支付'), (2, '待发货'), (3, '待收货'),  (5, '已完成')), verbose_name='订单状态')
    pay_method = models.SmallIntegerField(default=1, choices=((1, '支付宝'), (2, '微信')), verbose_name='支付方式')
    pay_time = models.DateTimeField(null=True, blank=True, verbose_name='支付时间')
    #冗余字段
    receiver_name = models.CharField(max_length=20, verbose_name='收件人')
    receiver_mobile = models.CharField(max_length=11, verbose_name='收件人电话')
    address = models.CharField(max_length=100, verbose_name='地址')

# orders/models.py
class OrderGoods(BaseModel):
    order_info = models.ForeignKey(
        'OrderInfo',
        on_delete=models.CASCADE,
        verbose_name='订单',
        to_field='order_id',  # 指定引用 order_id
        db_column='order_info_id'  # 保持现有列名
    )
    sku = models.ForeignKey('goods.SKU', on_delete=models.CASCADE, verbose_name='商品SKU')
    count = models.IntegerField(default=1, verbose_name='商品数量')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格')